﻿using System;
using System.Linq;
using System.Windows;
using Microsoft.Phone.Controls;

namespace ElectricityMate
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            // load saved measurements
            if (!App.ViewModel.IsDataLoaded) App.ViewModel.LoadData();
        }

        // go to measurement page
        private void StartBtn_OnClick(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MeasurementPage.xaml", UriKind.Relative));
        }

        // go to past measurements list page
        private void ShowDataBtn_OnClick(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/PastMeasurementsPage.xaml", UriKind.Relative));
        }

        private void SettingsBtn_OnClick(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
        }
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            while (NavigationService.BackStack.Any())
            {
                NavigationService.RemoveBackEntry();
            }
            base.OnBackKeyPress(e);
        }
    }
}